package com.hzj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzj.enums.OrderStatusEnum;
import com.hzj.mapper.OrderInfoMapper;
import com.hzj.pojo.OrderInfo;
import com.hzj.pojo.vo.user.OrderCountQueryVo;
import com.hzj.pojo.vo.user.OrderCountVo;
import com.hzj.service.OrderInfoService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {

    @Autowired
    private  OrderInfoMapper oim;

    @Override
    public boolean updateOrderInfo(OrderInfo orderInfo) {
        QueryWrapper  wrapper=new QueryWrapper();
        wrapper.eq("out_trade_no",orderInfo.getOutTradeNo());
        return saveOrUpdate(orderInfo,wrapper);
    }

    @Override
    public int selectCount() {
        return oim.selectCount();
    }

    @Override
    public Map<String, Object> getCountMap(OrderCountQueryVo orderCountQueryVo) {
        Map<String, Object> map = new HashMap<>();
        List<OrderCountVo> orderCountVoList = oim.selectOrderCount(orderCountQueryVo);
        List <String> dateList=new ArrayList<String>();
        List <Integer> countList=new ArrayList<Integer>();
        for(OrderCountVo orderCountVo:orderCountVoList){
            dateList.add(orderCountVo.getReserveDate());
            countList.add(orderCountVo.getCount());
        }
        map.put("dateList", dateList);
        map.put("countList", countList);
        return map;
    }

    @Override
    public List<OrderInfo> patientTips() {
        return null;
    }


}
